/**
 * @author Sebastian
 * @version 2.0
 * @date 2024/7/9 20:24
 */
// 验证二叉搜索树
    //https://leetcode.cn/problems/validate-binary-search-tree/
public class Solution98 {
    public boolean isValidBST(TreeNode root) {
        return isValidBSTHelper(root, null, null);
    }

    private boolean isValidBSTHelper(TreeNode root, TreeNode min, TreeNode max) {
        if (root == null) return true;
        if (min != null && root.val <= min.val ) return false;
        if (max != null && root.val >= max.val) return false;
        return isValidBSTHelper(root.left, min, root) && isValidBSTHelper(root.right, root, max);
    }
}
